/*
 * 1385. 动态数组 ArrayList
 * 用 ArrayList 实现一些操作：
 * create(n). 创建一个大小为n的ArrayList，包含n个整数，依次为[0, 1, 2, ... n-1]
 * clone(list). 克隆一个list。使得克隆后的list与原来的list是完全独立无关的。
 * get(list, index). 查询list中index这个位置的数。
 * set(list, index, val). 将list中index这个位置的数改为val。
 * remove(list, index). 移除list中index这个位置的数。
 * indexOf(list, val). 在list中查找值为val的数，返回它的index。如果没有返回-1。
 * 请使用 ArrayList 的原生方法完成这些操作。参见Java文档：ArrayList参考文档
 * 
 * 
 * 样例
 * ArrayList<Integer> list = ArrayListManager.create(5);
 * list.get(0);  // should return 0
 * list.get(1);  // should return 1
 * list.get(4);  // should return 4
 * // clone_list should be [0,1,2,3,4]
 * ArrayList<Integer> clone_list = ArrayListManager.clone(list);
 * ArrayListManager.get(list, 2);  // should return 2
 * ArrayListManager.indexOf(list, 1); // should return 1
 * ArrayListManager.indexOf(list, 10); // should return -1
 * ArrayListManager.remove(list, 3); // list will become [0, 1, 2, 4]
 * ArrayListManager.get(list, 3); // as 3 has been removed, should return 4
 * ArrayListManager.set(list, 2, 3); // list will become [0, 1, 3, 4]
 * clone_list.get(2); // should return 2
 * clone_list.get(3); // should return 3
 * 
 * 2018.06.10 @jeyming
 */
package arraylist_1385;

import java.util.ArrayList;

public class Arraylist_1385 {

    /**
     * @param n: You should generate an array list of n elements.
     * @return: The array list your just created.
     */
    public static ArrayList<Integer> create(int n) {
        // Write your code here
    	ArrayList<Integer> list = new ArrayList<Integer>();
    	for(int i = 0; i < n; ++i) {
    		list.add(i);
    	}
    	return list;
    }
    
    /**
     * @param list: The list you need to clone
     * @return: A deep copyed array list from the given list
     */
    public static ArrayList<Integer> clone(ArrayList<Integer> list) {
        // Write your code here
    	ArrayList<Integer> cloneList = new ArrayList<Integer>();
    	for(int i = 0; i < list.size(); ++i) {
    		cloneList.add(list.get(i));
    	}
    	return cloneList;
    }
    
    /**
     * @param list: The array list to find the kth element
     * @param k: Find the kth element
     * @return: The kth element
     */
    public static int get(ArrayList<Integer> list, int k) {
        // Write your code here
    	return list.get(k);
    }
    
    /**
     * @param list: The array list
     * @param k: Find the kth element, set it to val
     * @param val: Find the kth element, set it to val
     */
    public static void set(ArrayList<Integer> list, int k, int val) {
        // write your code here
    	list.set(k, val);
    }
    
    /**
     * @param list: The array list to remove the kth element
     * @param k: Remove the kth element
     */
    public static void remove(ArrayList<Integer> list, int k) {
        // write tour code here
    	list.remove(k);
    }
    
    /**
     * @param list: The array list.
     * @param val: Get the index of the first element that equals to val
     * @return: Return the index of that element
     */
    public static int indexOf(ArrayList<Integer> list, int val) {
        // Write your code here
    	return list.indexOf(val);
    }
	public static void main(String[] args) {
		// TODO Auto-generated method stub

	}

}
